package xin.luna;

import edu.princeton.cs.algs4.StdOut;

public class Test {
  public static void main(String[] args) {
    StdOut.println((0 + 15) / 2); // 7

    StdOut.println(2.0e-6 * 100000000.1); // 200.0000002

    StdOut.println(true && false || true && true); // true

    StdOut.println(getType((1 + 2.234) / 2)); // double

    StdOut.println(getType(1 + 2 + 3 + 4.0)); // double

    StdOut.println(4.1 >= 4); // true

    StdOut.println(1 + 2 + "3"); // 33

    StdOut.println(equal(1, 1, 3));
    StdOut.println(equal(1, 1, 1));

    StdOut.println(checkDouble(0.123, 0.456)); // true
    StdOut.println(checkDouble(0.123, 1.00000000001)); // false

    toBinaryString(123);

    StdOut.println(mystery(2, 25));
    //        StdOut.println(mystery(3, 11));
  }

  private static String getType(Object o) {
    return o.getClass().toString();
  }

  private static String equal(int a, int b, int c) {
    if (a == b && b == c) {
      return "equal";
    } else {
      return "not equal";
    }
  }

  private static boolean checkDouble(double x, double y) {
    return 0 < x && x < 1 && 0 < y && y < 1;
  }

  private static void fib() {
    int f = 0;
    int g = 1;
    for (int i = 0; i < 15; i++) {
      StdOut.println(f);
      f = f + g;
      g = f - g;
    }
  }

  private static void toBinaryString(int N) {
    String bs = "";

    for (int n = N; n > 0; n /= 2) {
      bs = (n % 2) + bs;
    }

    StdOut.println(bs);
  }

  private static int mystery(int a, int b) {
    if (b == 0) return 1;
    if (b % 2 == 0) return mystery(a * a, b / 2);
    return mystery(a * a, b / 2) * a;
  }
}
